﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD
{
    public abstract class AirUnit : Unit
    {
        protected float yaw = MathHelper.PiOver2, yawSpeed = 0.01f;

        public AirUnit(string unit)
            : base(unit, map.getAirStart(3), GegnerTyp.Luft)
        {
            speed = .01f;
        }

        public override void FixedGameUpdate()
        {
            Vector3 v = (position - new Vector3(baseTower.position.X, position.Y, baseTower.position.Z));
            if (v.Length() <= .5)
            {
                UnRegister(this);
                baseTower.Damage(lvlInfo.attackDmg);
                return;
            }
            v.Normalize();
            float newYaw = NormalizeAngle(Math.Atan2(v.X, v.Z));
            yaw = NormalizeAngle(Rotate(yaw, newYaw, yawSpeed));
            rotation = Matrix.CreateRotationY(yaw);

            position.X -= (float)(Math.Sin(yaw) * speed);
            position.Z -= (float)(Math.Cos(yaw) * speed);
        }
    }
}
